package site.lanmushan.framework.datascope.bean;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
/**
 * @author Administrator
 */
@Data
@EqualsAndHashCode
public class DataControlUserContext implements Serializable {
    private Long userId;
    private String deptCode;
    private String nickName;
    private String username;
    private String account;
    private Integer sex;
    private String headImgAddress;
    private List<String> roleCodes;
    private List<String> permittedList;

    /**
     * 判断是否存在某个角色
     * @param role
     * @return
     */
    public boolean hasRole(String ...role){
        if(roleCodes==null||role.length==0)
        {
           return false;
        }
        List<String> codes= Arrays.asList(role);

        return  roleCodes.stream().allMatch(codes::contains);
    }

    /**
     * 判断是否存在某个权限
     * @param permitted
     * @return
     */
    public boolean isPermitted(String ...permitted)
    {
        if(roleCodes==null||permitted.length==0)
        {
            return false;
        }
        List<String> codes= Arrays.asList();

        return  permittedList.stream().allMatch(codes::contains);
    }
    public static void main(String[] args) {
        DataControlUserContext dataControlUserContext =new DataControlUserContext();
        dataControlUserContext.setRoleCodes(Arrays.asList("admin"));
        System.out.println(dataControlUserContext.hasRole("admin"));
    }
}
